package pkg.customer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import retail.bo.CustomerBo;

public class CancelAction extends Action {
	private CustomerBo customerBo;
	public CustomerBo getCustomerBo() {
		return customerBo;
	}
	public void setCustomerBo(CustomerBo customerBo) {
		this.customerBo = customerBo;
	}
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		HttpSession session=request.getSession();
		DynaActionForm myForm=(DynaActionForm)form;
		String pid=myForm.getString("pid");
		String submit=myForm.getString("submit");
		if(submit.equals("Cancel")){
			boolean cancel=customerBo.removeProduct((String) session.getAttribute("username"), pid);
			if(cancel)
				return mapping.findForward("success");
			else
				mapping.findForward("failed");
		}
		session.setAttribute("selectedProduct", customerBo.getProduct(pid));
		
		return mapping.findForward("cancel");
	}

}
